#include "pch.h"
#include "seDoor.h"

//const sf::Input& mInputHero = app.GetInput(); 

void seDoor::Load(int number)
{
type=number-1;
frames=3;
string tmp;
sprintf((char*)tmp.c_str(), "%d", number);
string str = tmp.c_str();
for (int a=0;a<frames;a++){
	string actual;
	sprintf((char*)actual.c_str(), "%d", a);
	string actualny = actual.c_str();
	if (type==1) 
		mBackgroundLeft[a].LoadFromFile("data/door"+str+"_"+actualny+".png");
	else
		mBackgroundRight[a].LoadFromFile("data/door"+str+"_"+actualny+".png");
}
if (type==1) 
	mActiveSprite.SetImage(mBackgroundLeft[0]);
else
	mActiveSprite.SetImage(mBackgroundRight[0]);
}

void seDoor::Init()
{
	sf::Vector2f v1(viewWidth-930.0f,viewHeight- mActiveSprite.GetSize().y+10.0f);
	mActiveSprite.SetPosition(v1);
	counter=0;
	iCurrentFrame = 0;
}

void seDoor::Step(bool move)
{
	if (move){
		counter=31;
		cout<<"w drzwiach"<<endl;
	}
	if (counter>0){
		counter--;
	}
	if (counter%10==0 && counter>0){
		iCurrentFrame++;
		if (iCurrentFrame>=frames)
			iCurrentFrame=0;
		if (type==1) 
			mActiveSprite.SetImage(mBackgroundLeft[iCurrentFrame]);
		else
			mActiveSprite.SetImage(mBackgroundRight[iCurrentFrame]);
	}
	else if (counter==0){
		iCurrentFrame=0;
		if (type==1) 
			mActiveSprite.SetImage(mBackgroundLeft[0]);
		else	
			mActiveSprite.SetImage(mBackgroundRight[0]);
	}	
}

void seDoor::Draw()
{
	app.Draw(mActiveSprite);
}